import { WuXingGradeUpPanel } from "./WuXingGradeUpPanel";
import { Language } from "../../../../extend/language/Language";
import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { MsgManager } from "../../manager/MsgManager";
import { ItemData } from "../../resource/info/ItemData";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { ResFileConst } from "../../resource/ResFileConst";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { DeployPanelItem } from "../equipment/deploy/DeployPanelItem";
import { PetEquipStars } from "../petEquipment/deploy/PetEquipStars";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { TEquipShenglingConfig } from "../../../../Message/Db/Tables/TEquipShenglingConfig";
import { ECategory } from "../../../../Message/Public/ECategory";
import { WuXingRule } from "../../rules/WuXingRule";
import { CutDataUtil } from "../../../common/tools/CutDataUtil";
import { SWFPlayer } from "../../scene/modle/SWFPlayer";
import { ModelType } from "../../scene/modle/data/ModelType";
import { ModelInfo } from "../../scene/player/info/ModelInfo";
import { WuXingCache } from "../../cache/WuXingCache";
import { WuXingConfig } from "../../resource/WuXingConfig";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
type int = number;
//class WuXingShengLingPanel
    
    export  class WuXingShengLingPanel extends WuXingGradeUpPanel
    {
        constructor(arg1: int=428, arg2: int=438)
        {
            super(arg1, arg2);
            return;
        }

        public /* override */ updatePackData(): void
        {
            super.updatePackData();
            this.updateMaterialItem(_currentItem, this._tInfo);
            return;
        }

        public /* override */ updateMoney(): void
        {
            super.updateMoney();
            return;
        }

        protected /* override */ clear(): void
        {
            super.clear();
            this._tInfo = null;
            this._materilItem.itemData = null;
            this._curMaterialIdata = null;
            this._lvTx.text = "";
            this._wuxingFightTx.htmlText = Language.getStringByParam(73022, 0);
            this._wuxingIgnorTx.htmlText = Language.getStringByParam(73023, 0);
            this._costTx.htmlText = Language.getStringByParam(73016, 0);
            this._startLine.starNum = 0;
            return;
        }

        protected moneyCheck(): Boolean
        {
            var loc1=Cache.instance.login.loginGame.money.coin + Cache.instance.login.loginGame.money.coinBind;
            if (this._tInfo) 
            {
                if (this._tInfo.money > loc1) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, this._tInfo.money));
                    MsgManager.showRollTipsMsg(Language.getString(20038));
                    return false;
                }
            }
            return true;
        }

        /* internal  */materialNumCheck(): int
        {
            var loc1=0;
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc5=0;
            if (this._tInfo) 
            {
                loc2 = Cache.instance.pack.backPackCache._allItems;
                loc3 = loc2.length;
                loc5 = 0;
                while (loc5 < loc3) 
                {
                    if ((loc4 = loc2[loc5]) && !(loc4 == ItemData.nullItemData)) 
                    {
                        if (this.isFitItem(loc4)) 
                        {
                            loc1 = loc1 + loc4.itemAmount;
                        }
                    }
                    ++loc5;
                }
            }
            return loc1;
        }

        /* internal  */initNewStuff(): void
        {
            this._shenglingBm = ObjCreate.createBitmap("", 20, 17, this);
            this._shenglingLvBm = ObjCreate.createBitmap("", 94, 235, this);
            this._ignorBm = ObjCreate.createBitmap("", 37, 337, this);
            this._upDecTx = ObjCreate.createGTextField("", 15, 38, 235, 42, this);
            this._upDecTx.wordWrap = true;
            this._upDecTx.multiline = true;
            this._upDecTx.htmlText = Language.getString(73003);
            ObjCreate.createBg(5, 88, _bg2Width - 10, 2, this, ImagesConst.SplitLine);
            this._loadedBtn = ObjCreate.createGLoadedButton(ResFileConst.WuxingShenglingBtn, 247, 20, 48, 45, this);
            this._loadedBtn.toolTipData = Language.getString(73004);
            var loc1=new GImageBitmap("equipment_recast_recast.png", 150, 161);
            this.addChild(loc1);
            this._materilItem = new DeployPanelItem(0, true, false, "");
            this._materilItem.x = 199;
            this._materilItem.y = 164;
            this._materilItem.label = Language.getString(73005);
            addChild(this._materilItem);
            this._materilItem.item.isShowLock = false;
            this._startLine = new PetEquipStars();
            this._startLine.x = 47;
            this._startLine.y = 286;
            this._startLine.starMode = PetEquipStars.StarBig;
            this.addChild(this._startLine);
            this._allIgnorTx = ObjCreate.createGTextField("0", 247, 68, 48, 20, this, GlobalStyle.textFormat2);
            this._allIgnorTx.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._lvTx = ObjCreate.createGTextField("0", 192, 233, 60, 20, this, GlobalStyle.textFormatGreen);
            this._wuxingFightTx = ObjCreate.createGTextField("", 70, 259, 110, 20, this, GlobalStyle.textFormatGreen);
            this._wuxingIgnorTx = ObjCreate.createGTextField("", 175, 259, 110, 20, this, GlobalStyle.textFormatGreen);
            this._wuxingFightTx.toolTipData = Language.getString(73024);
            this._wuxingIgnorTx.toolTipData = Language.getString(73025);
            this._costTx = ObjCreate.createGTextField("", 109, 407, 130, 20, this);
            ObjCreate.createBitmap(ImagesConst.Tongqian_small, 200, 410, this);
            this._wuxingFightTx.htmlText = Language.getStringByParam(73022, 0);
            this._wuxingIgnorTx.htmlText = Language.getStringByParam(73023, 0);
            this._costTx.htmlText = Language.getStringByParam(73016, 0);
            LoaderHelp.addResCallBack(ResFileConst.wuxingShengling, this.onResoursLoadedHandler);
            return;
        }

        /* internal  */onResoursLoadedHandler(): void
        {
            this._shenglingBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.wuxingShenglingBm);
            this._shenglingLvBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.wuxingShenglingLvBm);
            this._ignorBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.wuxingShenglingEveryTenBm);
            return;
        }

        /* internal  */updateMaterialItem(arg1: ItemData, arg2: TEquipShenglingConfig): void
        {
            var loc1=null;
            var loc2=0;
            if (arg2 && arg1) 
            {
                loc1 = new ItemData(arg2.materialCode);
                if (loc1 && !(loc1 == ItemData.nullItemData)) 
                {
                    this._curMaterialIdata = loc1;
                    this._materilItem.itemData = this._curMaterialIdata;
                    this._materilItem.amount = arg2.materailNum;
                    loc2 = Cache.instance.pack.backPackCache.getItemCountByJudge(this.isFitItem);
                    this._materilItem.enabled = loc2 >= this._tInfo.materailNum ? true : false;
                }
            }
            return;
        }

        /* internal  */isFitItem(arg1: ItemData): Boolean
        {
            var loc1=false;
            if (arg1.category == ECategory._ECategoryProp) 
            {
                if (arg1.type == this._curMaterialIdata.type) 
                {
                    if (arg1.code == this._curMaterialIdata.code || arg1.code == this._curMaterialIdata.itemInfo.item.codeUnbind) 
                    {
                        loc1 = true;
                    }
                }
            }
            return loc1;
        }

        /* internal  */getStartNum(arg1: int, arg2: int): int
        {
            var loc1=WuXingRule.getCurLvMaxLv(arg1);
            if (arg2 == loc1) 
            {
                return 10;
            }
            var loc2;
            return loc2 = CutDataUtil.getUnitNum(arg2);
        }

        public updateShengLingStart(arg1: string, arg2: int): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            var loc4=0;
            var loc5=0;
            var loc6=0;
            if (!_currentItem) 
            {
                return;
            }
            if (_currentItem.uid != arg1) 
            {
                return;
            }
            if (arg2 > 0) 
            {
                loc1 = "equipEffect_petEquipStar.swf";
                if ((loc2 = CutDataUtil.getUnitNum(arg2)) != 0) 
                {
                    loc5 = loc2;
                }
                else 
                {
                    loc5 = 10;
                }
                this._startLine.starNum = loc5;
                loc6 = 0;
                while (loc6 < loc5) 
                {
                    loc3 = loc6 * 23 + 58;
                    loc4 = 298;
                    this.addStarEffect(loc1, loc3, loc4);
                    ++loc6;
                }
            }
            return;
        }

        /* internal  */addStarEffect(arg1: string, arg2: int, arg3: int): void
        {
            var loc1;
            (loc1 = new SWFPlayer()).sceneX = arg2;
            loc1.sceneY = arg3;
            loc1.framesPlayerCompleteHandler = this.onEffectPlayComplete;
            loc1.load(arg1, ModelType.Effect, new ModelInfo());
            this.addChild(loc1);
            return;
        }

        /* internal  */onEffectPlayComplete(arg1: SWFPlayer): void
        {
            arg1.dispose();
            return;
        }

        /* internal  */getMaterialArr(): Array<any>
        {
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc5=0;
            var loc1=[];
            if (this._tInfo) 
            {
                loc2 = Cache.instance.pack.backPackCache._allItems;
                loc3 = loc2.length;
                loc5 = 0;
                while (loc5 < loc3) 
                {
                    if ((loc4 = loc2[loc5]) && !(loc4 == ItemData.nullItemData)) 
                    {
                        if (this.isFitItem(loc4)) 
                        {
                            loc1.push(loc4.uid);
                        }
                    }
                    ++loc5;
                }
            }
            return loc1;
        }

        protected /* override */ initUI(): void
        {
            super.initUI();
            _itemList.isShowLingZhu = false;
            _quickLookFont.x = 10;
            _quickLookFont.y = 94;
            _quickLookBg.x = _quickLookFont.x + 20;
            _quickLookBg.y = _quickLookFont.y + 30;
            _quickLookItem.x = _quickLookBg.x + 10;
            _quickLookItem.y = _quickLookBg.y + 10;
            _optItem1.x = 94;
            _optItem1.y = 121;
            _optBtn1.label = Language.getString(73002);
            _optBtn1.x = 130;
            _optBtn1.y = 370;
            _hLine.y = 222;
            _line.y = 318;
            removeChild(_optBtn2);
            removeChild(_optItem2);
            removeChild(_arrowBg);
            removeChild(_degreeBar);
            removeChild(_degreeInfo);
            removeChild(_juhunCountBmp);
            removeChild(_juhunCountTxt);
            removeChild(_msgRollTips);
            _effectStartPoint = null;
            _effectEndPoint = null;
            this.initNewStuff();
            return;
        }

        protected /* override */ optAble(arg1: ItemData): Boolean
        {
            if (!arg1 || arg1 == ItemData.nullItemData) 
            {
                return false;
            }
            if (arg1.itemInfo.item.level < WuXingCache.SHENGLINGOPENLV) 
            {
                MsgManager.showRollTipsMsg(Language.getString(73018));
                return false;
            }
            return true;
        }

        protected /* override */ onOptBtn1ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            super.onOptBtn1ClickHandler(arg1);
            if (_currentItem) 
            {
                if (this.optAble(_currentItem)) 
                {
                    if (WuXingRule.isOverCurMaxSL(_currentItem.itemInfo.item.level, _currentItem.wxShenglingLV)) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(73019));
                        return;
                    }
                    if (this.moneyCheck()) 
                    {
                        if (this.materialNumCheck() >= this._tInfo.materailNum) 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.WuxingShengLingGoRIse, {"equipUid": _currentItem.uid, "materials": this.getMaterialArr()}));
                        }
                        else 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(71109));
                            return;
                        }
                    }
                }
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(26313));
            }
            return;
        }

        protected /* override */ updateCurrentItem(arg1: ItemData, arg2: Boolean=false): void
        {
            super.updateCurrentItem(arg1, arg2);
            if (arg1) 
            {
                this._tInfo = WuXingConfig.instance.getShengLingDetailInfo(_currentItem.wxShenglingLV);
                if (this._tInfo) 
                {
                    _optItem1.updateData("", _currentItem, 0, false);
                    this.updateMaterialItem(_currentItem, this._tInfo);
                    this._lvTx.text = _currentItem.wxShenglingLV + " / " + WuXingRule.getCurLvMaxLv(_currentItem.itemInfo.item.level);
                    this._wuxingFightTx.htmlText = Language.getStringByParam(73022, this._tInfo.addTotal);
                    this._wuxingIgnorTx.htmlText = Language.getStringByParam(73023, this._tInfo.ignoreRelief);
                    this._costTx.htmlText = Language.getStringByParam(73016, this._tInfo.money);
                    this._startLine.starNum = this.getStartNum(_currentItem.itemInfo.item.level, _currentItem.wxShenglingLV);
                }
            }
            else 
            {
                this._tInfo = null;
                this._curMaterialIdata = null;
            }
            return;
        }

        protected /* override */ updateMaxGradeItem(arg1: ItemData): void
        {
            super.updateMaxGradeItem(arg1);
            _quickLookItemData = WuXingRule.getShenglingBestIdata(arg1);
            _quickLookItem.itemData = _quickLookItemData;
            _quickLookItem.toolTipData = _quickLookItemData.getToolTipData();
            return;
        }

        public /* override */ updateRolePack(): void
        {
            super.updateRolePack();
            this._allIgnorTx.text = WuXingRule.getAllShengLingIgnor(Cache.instance.pack.rolePackCache.getEquipItems()).toString();
            return;
        }

        /* internal */ /* var */_startLine: PetEquipStars;

        /* internal */ /* var */_shenglingBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_shenglingLvBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_ignorBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_upDecTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_materilItem: DeployPanelItem;

        /* internal */ /* var */_loadedBtn: GLoadedButton;

        /* internal */ /* var */_lvTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_wuxingFightTx: GTextFiled;

        /* internal */ /* var */_wuxingIgnorTx: GTextFiled;

        /* internal */ /* var */_costTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_allIgnorTx: GTextFiled;

        /* internal */ /* var */_tInfo: TEquipShenglingConfig;

        /* internal */ /* var */_curMaterialIdata: ItemData;
    }
